package com.atguigu.job;

import com.atguigu.utils.QiniuUtils;
import com.atguigu.constant.RedisConstant;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Iterator;
import java.util.Set;

/**
 * @program: meinian_parent
 * @author: Mr.Zhuo
 * @create: 2022-02-16 10:55
 **/
public class ClearImgJob {

    @Autowired
    JedisPool jedisPool;

    public void clearImg() {
        //  获得垃圾图片的资料
        Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);

        Iterator<String> iterator = set.iterator();

        while (iterator.hasNext()) {
            String pic = iterator.next();
            System.out.println("删除的图片名称为"+pic);
            // 删除七牛云上的数据
            QiniuUtils.deleteFileFromQiniu(pic);
            //删除redis中的数据
            jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,pic);

        }

    }
}
